package com.gaowl.yygh.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gaowl.yygh.commom.result.Result;
import com.gaowl.yygh.model.user.UserInfo;
import com.gaowl.yygh.user.service.UserInfoService;
import com.gaowl.yygh.vo.user.UserInfoQueryVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @program: appointment-register
 * @description: 平台管理系统的用户控制器类
 * @author: gaowl@stu.jiangnan.edu.cn
 * @create: 2021-04-07 08:25
 **/
@RestController
@RequestMapping("/admin/user")
public class UserController {

    @Autowired
    private UserInfoService userInfoService;

    /**
     * @Description: 查询用户列表
     * @Author: gaowl@stu.jiangnan.edu.cn
     * @Date: 2021/04/08
     */
    @GetMapping("{page}/{limit}")
    public Result list(@PathVariable Long page, @PathVariable Long limit, UserInfoQueryVo userInfoQueryVo) {
        System.out.println(userInfoQueryVo);

        Page<UserInfo> pageParam = new Page<>(page, limit);
        IPage<UserInfo> pageModel = userInfoService.selectPage(pageParam, userInfoQueryVo);
        return Result.ok(pageModel);
    }

    /**
     * @Description: 锁定用户
     * @Author: gaowl@stu.jiangnan.edu.cn
     * @Date: 2021/04/08
     */
    @GetMapping("lock/{userId}/{status}")
    public Result lock(
            @PathVariable("userId") Long userId,
            @PathVariable("status") Integer status){  // 0：锁定，1：正常
        userInfoService.lock(userId, status);
        return Result.ok();
    }

    /**
     * @Description: 查看用户详情
     * @Author: gaowl@stu.jiangnan.edu.cn
     * @Date: 2021/04/08
     */
    @GetMapping("show/{userId}")
    public Result show(@PathVariable Long userId) {
        Map<String,Object> map = userInfoService.show(userId);
        return Result.ok(map);
    }


    /**
     * @Description: 审批用户的认证信息
     * @Author: gaowl@stu.jiangnan.edu.cn
     * @Date: 2021/04/08
     */
    @GetMapping("approval/{userId}/{authStatus}")
    public Result approval(@PathVariable Long userId,@PathVariable Integer authStatus) {
        userInfoService.approval(userId,authStatus);
        return Result.ok();
    }


}